class Admin::VersionsController < Admin::AdminController
  filter_resource_access :additional_collection => {:revert => :update}

  def revert
    @version = Version.find(params[:id])
    
    if @version.reify
      @version.reify.save!
    else
      @version.item.destroy
    end

    link_name = params[:redo] == "true" ? "Vzít zpět" : "Znovu provést změny."
    link = view_context.link_to(link_name, revert_version_path(@version.next, :redo => !params[:redo]), :method => :post)
    redirect_to :back, :notice => "#{t @version.event}. #{link}."
  end

  def show
  end

  def destroy
    if @version.destroy
      flash[:notice] = "Verze byla úspěšně smazána."
    else
      flash[:error] = "Verzi se nepodařilo smazat."
    end

    redirect_to :back
  end
end
